/*
 * @Descripttion: 
 * @version: 
 * @Author: weni09
 * @Date: 2021-04-20 14:19:51
 * @LastEditors: weni09
 * @LastEditTime: 2021-06-11 21:42:56
 * @FilePath: \icoder-frontend\blog\src\api\index.js
 */
import request from '@/utils/axios';
import { setDateFormat } from '@/utils';


export function fetchArticleList(params={}){
    return request({
        url: '/article_list',
        method: 'get',
        params: {
            res: params.res,
            slug: params.slug,
            offset: params.offset || 0,
            limit: params.limit || 10,
            sort: params.sort || 'id'
        },
        transformResponse: [function (data) {
          var dataObj = JSON.parse(data)
          setDateFormat(dataObj,'create_date','{Y}/{m}/{d} {h}:{i}');
          setDateFormat(dataObj,'update_date','{Y}/{m}/{d}');
        // console.log("data,"+data)
        return dataObj
        }],
    })
};
export function fetchTags(){
    return request({
        url: '/res/tag',
        method: 'get',
        params: {}

    })
};
export function fetchCategories(){
    return request({
        url: '/res/category',
        method: 'get',
        params: {}
    })
};

export function fetchArtDetail(params){
    return request({
        url: '/artDetail/' + params.id,
        method: 'get',
        params: {},
        transformResponse: [function (data) {
            var dataObj = JSON.parse(data)
           setDateFormat(dataObj,'create_date','{Y}年{m}月{d}日');
           setDateFormat(dataObj,'update_date','{Y}/{m}/{d} {h}:{i}:{s}');
         return dataObj
         }],
    })
};

export function updateViews(params){
    return request({
        url: '/artViews/update',
        method: 'post',
        data: params,
        timeout: 10000,
    })
};

export function addComment(params){
    return request({
        url: '/comment/add',
        method: 'post',
        data: params,
        timeout: 10000,
    })

};

export function fetchComment(params){
    return request({
        url: '/comment/' + params.id,
        method: 'get',
        params:{},
        timeout: 10000,
    })

};

export function loginIn(params){
    return request({
        url: '/login',
        method: 'post',
        data: params,
        timeout: 10000,
    })
};

export function updateTokenApi(params){
    return request({
        url: '/token/refresh',
        method: 'post',
        data: params,
        timeout: 10000,
    })
}

export function addArticle(params){
    return request({
        url: '/article/edit',
        method: 'post',
        data: params,
        timeout: 10000,
    })
}


//删除文件接口
export function deleteFile(params){
    return request({
        url: '/file/delete',
        method: 'post',
        data: params,
        timeout: 10000,
    })
}
export function fetchAbout(params){
    return request({
        url: '/about/query/' + params.id,
        method: 'get',
        params:{},
        timeout: 10000,
    })

};

//编辑关于
export function editAbout(params){
    return request({
        url: '/about/edit',
        method: 'post',
        data: params,
        timeout: 10000,
    })
}

//注册用户
export function register(params){
    return request({
        url: '/register',
        method: 'post',
        data: params,
        timeout: 10000,
    })
}